package com.aichat.ai_chatbackend.controller;

import com.aichat.ai_chatbackend.common.BaseResponse;
import com.aichat.ai_chatbackend.service.impl.CompanionChatService;
import com.aichat.ai_chatbackend.utils.ResultUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/performance")
@Tag(name = "性能监控", description = "系统性能监控和缓存管理")
@Slf4j
public class PerformanceController {

    @Autowired
    private CompanionChatService companionChatService;



    @GetMapping("/ai-service/health")
    @Operation(summary = "AI服务健康检查", description = "检查AI服务的健康状态")
    public BaseResponse<Map<String, Object>> checkAiServiceHealth() {
        try {
            boolean isHealthy = companionChatService.isAiServiceHealthy();
            Map<String, Object> health = new HashMap<>();
            health.put("status", isHealthy ? "healthy" : "unhealthy");
            health.put("timestamp", System.currentTimeMillis());
            return ResultUtils.success(health);
        } catch (Exception e) {
            log.error("AI服务健康检查失败: {}", e.getMessage(), e);
            return ResultUtils.error(500, "健康检查失败");
        }
    }
} 